<template>
  <el-row :gutter="16" class="panel-group">
    <el-col v-for="(item, index) in cards" :key="index" :xs="12" :sm="12" :lg="4" class="card-panel-col">
      <card :type="item.type" :param="item.param" />
    </el-col>
    <el-col :xs="12" :sm="12" :lg="8" class="card-panel-col">
      <card class="udf-card-3" type="3">
        <div class="top">
          <span class="title">O2O平台接入</span>
        </div>
        <div class="bottom">
          <div class="item">
            <div class="info">
              <span class="label">美团：</span>
              <span class="text"><count-to :start-val="0" :end-val="formModel.meituanDeviceCount" :duration="2600" class="money" />台</span>
            </div>
            <div class="info">
              <span class="label">累计订单：</span>
              <span class="text"><count-to :start-val="0" :end-val="formModel.meituanOrderCount" :duration="2600" class="money" /></span>
            </div>
          </div>
          <div class="item">
            <div class="info">
              <span class="label">京东：</span>
              <span class="text"><count-to :start-val="0" :end-val="formModel.jddjDeviceCount" :duration="2600" class="money" />台</span>
            </div>
            <div class="info">
              <span class="label">累计订单：</span>
              <span class="text"><count-to :start-val="0" :end-val="formModel.jddjOrderCount" :duration="2600" class="money" /></span>
            </div>
          </div>
        </div>
      </card>
    </el-col>
  </el-row>
</template>

<script>

export default {
  name: 'PanelGroup',
  components: {
    Card: () => import('./Card'),
    CountTo: () => import('vue-count-to')
  },
  data() {
    return {
      formModel: {
        meituanDeviceCount: 0,
        jddjDeviceCount: 0,
        meituanOrderCount: 0,
        jddjOrderCount: 0
      },
      cards: [{
        type: '1',
        field: 'totalAmount',
        param: {
          title: '累计销售额',
          money: 0,
          decimals: 2,
          desc: '注：O2O销售未计入'
        }
      }, {
        type: '1',
        field: 'medicineTotalCount',
        param: {
          title: '累计销量',
          money: 0,
          decimals: 0,
          desc: '注：O2O销售未计入'
        }
      }, {
        type: '2',
        field: 'todayTotalAmount',
        param: {
          title: '当日销售额',
          money: 0,
          decimals: 2,
          desc: '注：O2O销售未计入'
        }
      }, {
        type: '2',
        field: 'todayMedicineTotalCount',
        param: {
          title: '当日销量',
          money: 0,
          decimals: 0,
          desc: '注：O2O销售未计入'
        }
      }]
    }
  },
  mounted() {
    this.query()
  },
  methods: {
    query() {
      this.get('/order/getIndexSalesSummaryData', null, { showLoading: false }).then(ret => {
        this.cards.forEach(item => {
          const field = item.field
          item.param.money = ret[field] || 0
        })
        this.assignData(ret.indexO2OSalesData, this.formModel)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .udf-card-3 {
    .bottom {
      flex: 1;
      flex-direction: column;
      .item {
        display: flex;
        .info {
          &:not(:last-child) {
            margin-right: 22px;
          }
        }
      }
    }
  }
.panel-group {

  .card-panel-col {
    margin-bottom: 16px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #FC7009;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>
